//
//  HomeViewTopCell.m
//  StormWatch
//
//  Created by 王岩 on 2024/8/30.
//

#import "HomeViewTopCell.h"

@implementation HomeViewTopCell

- (void)updateTheme {
    self.hotLab.textColor = self.hotUnitLab.textColor = self.hotValueLab.textColor = self.distanceLab.textColor = self.distanceUnitLab.textColor = self.distanceValueLab.textColor = [ThemeManager sharedInstance].textColor;

    self.circleProgressView.pathBackColor = [ThemeManager sharedInstance].circleBackColor;
    self.circleProgressView.pathFillColor = [ThemeManager sharedInstance].circleFillColor;
    
}

- (void)updateValueStep:(NSString *)step Distance:(NSString *)distance Hot:(NSString *)hot{
    self.hotUnitLab.text = SWString(@"Kcal");
    self.hotLab.text = SWString(@"Heat");
    
    self.distanceLab.text = SWString(@"Distance");
    self.distanceUnitLab.text = SWString(@"Km");
    self.circleProgressView.showPoint = NO;//是否显示默认小圆点。默认为YES·\
    
    NSString * num = [NSString stringWithFormat:@"%@\n",step];
    self.circleProgressView.progressLabel.numberOfLines = 2;
    self.circleProgressView.progressLabel.attributedText = [SWTool attS1:num s2:SWString(@"Step") f1:S_bfont(28) c1:[ThemeManager sharedInstance].textColor f2:S_font(16) c2:[ThemeManager sharedInstance].textColor];
    
    self.hotValueLab.text = [NSString stringWithFormat:@"%@",hot];
    self.distanceValueLab.text = [NSString stringWithFormat:@"%@",distance];
    int target = [[[NSUserDefaults standardUserDefaults] valueForKey:@"Storm_steptarget"] intValue];
    if (target > 0) {
        self.circleProgressView.progress = (float)step.integerValue / (float)target;
    }else {
        self.circleProgressView.progress = 0;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.circleProgressView.reduceAngle = 0;//整合进度条缺少30度
//    self.circleProgressView.pointImage.image = [UIImage imageNamed:@"test"];//设置小圆点图片
    self.circleProgressView.duration = 0.0;//动画时长。默认为1.5
    self.circleProgressView.showProgressText = NO;//是否显示默认进度文本。默认为YES
    self.circleProgressView.increaseFromLast = NO;//进度条动画是否从上次进度开始动画。默认为NO
    self.circleProgressView.startAngle = -90;
    self.circleProgressView.strokeWidth = 25;
    
    self.circleProgressView.userInteractionEnabled =  YES;
    [self.circleProgressView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCircleProgressView)]];
    
    self.hotLab.userInteractionEnabled = self.hotUnitLab.userInteractionEnabled = self.hotValueLab.userInteractionEnabled = YES;
    self.distanceLab.userInteractionEnabled = self.distanceUnitLab.userInteractionEnabled = self.distanceValueLab.userInteractionEnabled = YES;
    
    [self.hotLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickHeat)]];
    [self.hotUnitLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickHeat)]];
    [self.hotValueLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickHeat)]];
    
    
    [self.distanceLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickDistance)]];
    [self.distanceUnitLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickDistance)]];
    [self.distanceValueLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickDistance)]];
    
    // Initialization code
}

- (void)clickCircleProgressView {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickCircleView)]) {
        [self.delegate clickCircleView];
    }
}

- (void)clickHeat {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickHotView)]) {
        [self.delegate clickHotView];
    }
}

- (void)clickDistance {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickDistanceView)]) {
        [self.delegate clickDistanceView];
    }
}
@end
